#include <stdio.h> 
#include <string.h>
#include <sys/time.h>
#include "role.h"
#include "test_mgr.h"


int main(int argc, char **argv) {
    if (argc < 2) {
        fprintf(stderr, "usage:%s role, choice <server, client>\n", *argv);
        return -1;
    }

    role_type type = role_none;
    int is_server = strncmp(*(argv + 1), "server", 6);
    bool is_client = strncmp(*(argv + 1), "client", 6);

    type = is_server == 0 ? role_server : type;
    type = is_client== 0 ? role_client : type;

    uv_loop_t* loop = uv_default_loop();
    if (loop == nullptr) {
        printf("create default loop error\n");
        return -1;
    }

    switch (type) {
        case role_server: {
            role test_role(loop);
            test_role.init(type);
            }
            break;
        case role_client:
            test_mgr::get()->start_login();
            break;
        default:
            break;
    }
    uv_run(loop, UV_RUN_DEFAULT);
    
    return 0;
}
